#include "Int_One_Key.h"
#include "Dri_Timer_2.h"
#include "Dri_Grip.h"
#include "Int_OLED_Data.h"

/** 按钮1 的溢出率 */
static u8 s_key1_overflow = 0Xff;
/** 按钮2 的溢出率 */
static u8 s_key2_overflow = 0Xff;

/** 默认是抬起状态 */
static bit s_key1_state = 1;
/** 默认是抬起状态 */
static bit s_key2_state = 1;

/**
 * @brief
 * 定时数据
 */
void App_Model_Timer_Back()
{
    s_key1_overflow <<= 1;
    s_key1_overflow |= KEY_SW1;

    s_key2_overflow <<= 1;
    s_key2_overflow |= KEY_SW2;
}

/**
 * @brief 按键初始化
 *
 * @return u8
 */
void Int_Key_Init()
{
    Dri_Timer_AddCallBack(App_Model_Timer_Back);
}

/**
 * @brief 按键1 状态
 *
 * @return u8
 */
u8 Int_Key1_State()
{
    if (s_key1_state == 1 && s_key1_overflow == 0X00) {

        s_key1_state = 0;
        return 1;
    }
    // 上次是按下状态,现在是抬起来的状态
    if (s_key1_state == 0 && s_key1_overflow == 0Xff) {

        s_key1_state = 1;
        return 2;
    }

    return 0;
}

/**
 * @brief 按键2 状态
 *
 * @return u8
 */
u8 Int_Key2_State()
{
    // 上次是按下状态,现在是抬起来的状态
    if (s_key2_state == 0 && s_key2_overflow == 0Xff) {

        s_key2_state = 1;
        return 2;
    }
    if (s_key2_state == 1 && s_key2_overflow == 0X00) {

        s_key2_state = 0;
        return 1;
    }

    return 0;
}